<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="hello">
        <cpn :pnum1='num1' @zidingyishijian='chulizishuju'></cpn>
    </div>
    <template id="temp1">
        <div>
            <!-- 父组件 -->
            <h5>{{pnum1}}</h5>
            
            <!-- 需求：希望输入的值能改变props里的值 
                不允许vmodel直接绑定pnum1 因为这里面vmodel会修改pnum，父组件里的data也会修改pnum,可能会造成冲突
                正确做法应该在组件的data里面创建新的字段
            -->
            <!-- <input type="text" v-model="dataNumber1"> -->
            
            <!-- 子组件数据 -->
            <input type="text" :value='dataNumber1' @input='input1'>
        </div>
    </template>
    <script src="../../vue.js"></script>
    <script>
        const vue01 = new Vue({
            el: '#hello',
            data: {
                num1: 0,
            },
            methods: {
                //这个方法处理自定义事件 子组件传来的数据 
                chulizishuju(dataNumber){
                    this.num1 =  dataNumber;
                }
            },
            components: {
                cpn: {
                    template: '#temp1',
                    //为了拿到父组件的num1 num2 所以要定义pnum
                    props: {
                        pnum1: Number,
                    },
                    data() {
                        return {
                            dataNumber1:0000,
                        }
                    },
                    methods: {
                        input1(event){
                            //event.target.value 拿到用户输入的值
                            this.dataNumber1 = parseInt(event.target.value);
                            //调用emit事件向父组件发送数据
                            this.$emit('zidingyishijian',this.dataNumber1);
                        }
                    },
                }
            },

        })
    </script>
</body>

</html>